require 'sinatra'
require_relative '../lib/aboutyou-sdk.rb'

class AY
  attr_accessor :result
  
  def puts_cat_name(category)
      category = Array(category)
      self.result = self.result + '<ul>'
      category.each do |cat|
        self.result = self.result + ('<li>'+cat.name+'</li>')
        if (cat.subcategories(true))
              putsCatName(cat.subcategories(true))
        else
          puts ""
        end
      end
      self.result = self.result + '</ul>'
      return result
  end
end

shop = AY.new(281, 'e6068c4ca020262613d06122663cb300')

get "/" do
  shop.result = ""
  autocompleteResult = shop.fetch_autocomplete("ho", 15)
  autocompleteResult.products.each do |prod|
    shop.result = shop.result + prod.name + '</br>'
  end
  
  shop.result = shop.result + '</br>'
  
  autocompleteResult.categories.each do |cat|
    shop.result = shop.result + cat.name + '</br>'
  end
  
  return shop.result
end